package gummachine.state;

import gummachine.GumballMachine;

public class SoldState implements State {
    transient private GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("a gum ball will come soon,you needn't insert quarter now");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("Sorry, you turned the crank already");
    }

    @Override
    public void turnCrank() {
        System.out.println("Sorry, you turned the crank already, ready for your gum ball");
    }

    @Override
    public void dispense() {
        gumballMachine.releaseBall();
        System.out.println("Get the gum ball!!");
        if (gumballMachine.getCount() > 0) {
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("sold out~~~");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }


    }
}
